<template>
  <div>
    <!-- 顶部导航 -->
    <van-nav-bar title="编辑个性签名">
      <template #left>
        <span @click="$emit('close')">
          <svg-icon style="margin-left: 10px;" icon-class='fanhui' width="30px" height="30px" class="icon"/>
        </span>
      </template>
    </van-nav-bar>
    <!-- 文本结构 -->
    <div style="padding: 8px;">
      <van-field
        v-model="message"
        rows="2"
        autosize
        type="textarea"
        maxlength="30"
        placeholder="请输入昵称"
        show-word-limit
      />
    </div>
    <div style="margin: 20px;">
      <van-button round block type="info" color="#ec87c0" @click="onConfirm">提交</van-button>
    </div>
  </div>
</template>

<script>
import { updateUserProfileAPI } from '../../../api/index.js'

export default {
  name: 'SignatureEdit',

  props: {
    userSignature: {
      type: String,
      default: ''
    }
  },

  data () {
    return {
      message: this.userSignature
    }
  },

  methods: {
    // 点击确认
    async onConfirm () {
      try {
        await updateUserProfileAPI({
          signature: this.message
        })

        this.$toast.success('修改成功')

        // 修改成功后需要关闭页面，并更新昵称
        // 更新昵称
        this.$emit('update:userSignature', this.message)

        // 关闭弹框
        this.$emit('close')
      } catch (error) {
        console.log(error)
        this.$toast.fail('修改失败')
      }
    }
  }
}
</script>

<style>

</style>
